package yunwo.cn.yzstation.model;

import android.util.Log;
import android.widget.Toast;

import com.google.gson.Gson;
import com.zhy.http.okhttp.callback.StringCallback;

import java.util.HashMap;
import java.util.Map;

import okhttp3.Call;
import yunwo.cn.yzstation.api.HttpManager;
import yunwo.cn.yzstation.api.IassembleModel;
import yunwo.cn.yzstation.api.okapi.GLCallBack;
import yunwo.cn.yzstation.bean.CarListBean;
import yunwo.cn.yzstation.config.MyConstants;
import yunwo.cn.yzstation.presenter.AssembleActivityPersenter;
import yunwo.cn.yzstation.utils.StringUtil;
import yunwo.cn.yzstation.view.activity.AssembleActivity;

/**
 * Created by lao on 2017/10/12.
 */
public class AssembleModel {
    AssembleActivity assembleActivity;
    IassembleModel iassembleModel;

    public AssembleModel(AssembleActivity assembleActivity, IassembleModel iassembleModel) {
        this.assembleActivity = assembleActivity;
        this.iassembleModel = iassembleModel;
    }

    public void getlistData(final String type,int page,String orgtype) {
        Map<String, Object> map = new HashMap<>();
        map.put("isShort", orgtype);
        map.put("isStowage", "1");
        map.put("status", "");
        HttpManager.hpptPostPageStringmer(MyConstants.carlist,page,10,map).execute(new GLCallBack() {
            @Override
            public void onResponseT(String result, int code, String msg, int id) {
                if (code == 200) {
                    if (!StringUtil.isEmpty(result)) {
                        CarListBean.DataBean dataBean = new Gson().fromJson(result, CarListBean.DataBean.class);
                        iassembleModel.getlistDataSuccess(dataBean,type);
                    }
                }else {
                    iassembleModel.getlistDatafailure();
                    Toast.makeText(assembleActivity, msg, Toast.LENGTH_SHORT).show();
                }
            }

            @Override
            public void onError(Call call, Exception e, int id) {

                iassembleModel.getlistDatafailure();
            }
        });
    }
}
/**/